import 'dart:async';

import 'package:flutter/material.dart';
import 'package:laksa/screens/news_screen2.dart';
import 'package:laksa/services/news_service.dart';

class NewsScreenState2 extends State<NewsScreen2> {

  final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey = new GlobalKey<
      RefreshIndicatorState>();

  Future<Null> _handleRefresh() async {
    print('refresh');
    return null;
  }

  bool _onNotification<Notification>(Notification n) {
    print('loadMore');
    if (n is! OverscrollNotification) {
      return true;
    }
//    _loadMore();
    return true;
  }

  @override
  build(BuildContext context) =>
      new NotificationListener(
        key: _refreshIndicatorKey,
        onNotification: _onNotification,
        child: new RefreshIndicator(
          child: new ListView.builder(
              itemCount: 2,
              physics: const AlwaysScrollableScrollPhysics(),
              padding: const EdgeInsets.only(top: 10.0, bottom: 10.0),
              itemBuilder: (BuildContext context, int index) {
                return NewsService.getNews(context, 2, index);
              }
          ),
          onRefresh: _handleRefresh,
        ),
      );
}